package com.apes.framework.plugin.workflow.parser.element;

import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import com.apes.framework.plugin.workflow.parser.node.WorkflowNodeParser;
import com.apes.framework.util.LogicalUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能：executor元素解析器
 *
 * @author xul
 * @create 2018-06-30 11:33
 */
@Component
public class ExecutorElementParser implements ApesElementParser<ApesElement, List<String>> {

    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"before", "after"};

    /**
     * 功能：可解析的节点或元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return WorkflowNodeParser.domain;
    }

    /**
     * 功能：元素解析
     *
     * @param element
     */
    @Override
    public List<String> parse(ApesElement element) {
        List<String> esbIds = new ArrayList();
        element.getNestedElements().stream().filter(e -> e.getName().equalsIgnoreCase("esb")).forEach(e -> {
            esbIds.add(e.parse());
        });
        return esbIds;
    }
}
